package com.ucar.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/**
 * adapter基类
 * @author Administrator
 *
 * @param <T>
 */
public abstract class AbstractAdapter<T> extends BaseAdapter 
{
	protected Context mContext;
	private ArrayList<T> items = new ArrayList<T>();
	
	public AbstractAdapter( Context mContext )
	{
		this.mContext = mContext;
	}
	
	/**
	 * 清除数据
	 */
	public void recycle()
	{
		items.clear();
	}
	
	/**
	 * 添加数据
	 * @param items
	 * @param isRefresh 是否刷新
	 */
	public void add( ArrayList<T> items, boolean isRefresh )
	{
		this.items.clear();
		this.items.addAll( items );
		if ( isRefresh )
		{
			notifyDataSetChanged();
		}
	}
	
	@Override
	public int getCount() 
	{
		return items.size();
	}

	@Override
	public T getItem(int position) 
	{
		return items.get( position );
	}

	@Override
	public long getItemId(int position) 
	{
		return 0;
	}

	@Override
	public abstract View getView(int position, View convertView, ViewGroup parent);

}
